package cn.sdormitory.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.sdormitory.sys.dao.SysNoticeDao;
import cn.sdormitory.sys.dao.SysRoleDeptDao;
import cn.sdormitory.sys.entity.SysNotice;
import cn.sdormitory.sys.entity.SysRole;
import cn.sdormitory.sys.entity.SysRoleDept;
import cn.sdormitory.sys.service.SysNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysNoticeService")
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeDao, SysNotice> implements SysNoticeService {

    @Autowired
    private SysNoticeDao sysNoticeDao;

    @Override
    public SysNotice getOneSysNotice() {
        SysNotice sysNotice = new SysNotice();
        LambdaQueryWrapper<SysNotice> wrapper = new LambdaQueryWrapper<>(sysNotice);
        wrapper.eq(SysNotice::getNoticeStatus,"0");
        wrapper.orderByDesc(SysNotice::getCreatedTime);


        List<SysNotice> list = sysNoticeDao.selectList(wrapper);
        if(list!=null&&list.size()>0){
            SysNotice snVO = list.get(0);
            snVO.setNoticeStatus("1");
            sysNoticeDao.updateById(snVO);
            return snVO;
        }
        return null;
    }

    @Override
    public int updateNoticeStatus(SysNotice notice) {
        return sysNoticeDao.updateById(notice);
    }
}
